package com.mairuide.idnumber.service;

import com.mairuide.bill.DealFlow;
import com.mairuide.casemanage.dao.CaseManageDao;
import com.mairuide.idnumber.dao.IdNumberDetailDao;
import com.mairuide.idnumber.pojo.IdNumberDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;

/**
 * Created by 敲代码的卡卡罗特
 * on 2019/1/9 15:21.
 */
@Service
public class IdNumberDetailService {
    @Autowired
    private IdNumberDetailDao idNumberDetailDao;
    @Resource
    JdbcTemplate jdbcTemplate;

    public void batchSave(List<IdNumberDetail> list) {
        if(list!=null && list.size()>0){
            final List<IdNumberDetail> tempList = list;
            String sql="insert into TB_ID_NUMBER_DETAIL(ID, ID_NUMBER, NAME, SERVICE_ADDR, JOB, HOME_ADDR, NATIVE_PLACE) ";
            sql+="values(SEQ_ID_NUMBER_DETAIL.nextval,?,?,?,?,?,?) ";
            jdbcTemplate.batchUpdate(sql,
                    new BatchPreparedStatementSetter() {
                        public void setValues(PreparedStatement ps, int i)
                                throws SQLException {
                            ps.setString(1, tempList.get(i).getIdNumber()==null?"":tempList.get(i).getIdNumber());
                            ps.setString(2, tempList.get(i).getName()==null?"":tempList.get(i).getName());
                            ps.setString(3, tempList.get(i).getServiceAddr()==null?"":tempList.get(i).getServiceAddr());
                            ps.setString(4, tempList.get(i).getjOB()==null?"":tempList.get(i).getjOB());
                            ps.setString(5, tempList.get(i).getHome_addr()==null?null:tempList.get(i).getHome_addr());
                            ps.setString(6, tempList.get(i).getNativePlace()==null?"":tempList.get(i).getNativePlace());
                        }
                        public int getBatchSize() {
                            return tempList.size();
                        }
                    });
        }
    }
}
